import { ObjCreate } from "../../common/ObjCreate";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { FrameTimer } from "../../../../../com/gengine/core/frame/FrameTimer";
import { TimerType } from "../../../../../com/gengine/core/frame/TimerType";
import { RemainTimeTool } from "../../award/RemainTimeTool";
import { GLabel } from "../../../../../com/mui/controls/GLabel";
type int = number;
//class CopyGradeRollLabel
    
    export  class CopyGradeRollLabel /* flash.display.Sprite */
    {
        constructor(arg1: string)
        {
            
            this._type = arg1;
            this._label = ObjCreate.createLabel("", 0, 0, 70, 20, flash.text.TextFormatAlign.LEFT, this, true);
            this._labelValue = ObjCreate.createLabel("", 65, 0, 70, 20, flash.text.TextFormatAlign.LEFT, this, true);
            return;
        }

        public updateValue(arg1: int): void
        {
            this._value = arg1;
            this._currentValue = 0;
            this._gap = arg1 / 30;
            if (this._gap < 1) 
            {
                this._gap = 1;
            }
            return;
        }

        public set gap(arg1: int)
        {
            this._gap = arg1;
            return;
        }

        public set label(arg1: string)
        {
            this._label.htmlText = HTMLUtil.addColor(arg1, GlobalStyle.color1);
            return;
        }

        public set labelFilters(arg1: Array<any>)
        {
            this._label.textField.filters = arg1;
            return;
        }

        public startRoll(): void
        {
            if (!this._frame) 
            {
                this._frame = new FrameTimer();
                this._frame.addListener(TimerType.ENTERFRAME, this.onEnterFrame);
            }
            this._frame.start();
            return;
        }

        /* internal  */onEnterFrame(arg1: FrameTimer): void
        {
            this._currentValue = this._currentValue + this._gap;
            if (this._currentValue > this._value) 
            {
                this._currentValue = this._value;
            }
            if (this._type != CopyGradeRollLabel.Number) 
            {
                if (this._type == CopyGradeRollLabel.Time) 
                {
                    this._labelValue.htmlText = HTMLUtil.addColor(RemainTimeTool.getRemainTimeBySeconds(this._currentValue), GlobalStyle.color1);
                }
            }
            else 
            {
                this._labelValue.htmlText = HTMLUtil.addColor(String(this._currentValue), GlobalStyle.color1);
            }
            if (this._currentValue >= this._value) 
            {
                if (this._frame) 
                {
                    this._frame.stop();
                    this._frame.dispose();
                    this._frame = null;
                }
            }
            return;
        }

        public reset(): void
        {
            this._label.htmlText = "";
            this._labelValue.htmlText = "";
            if (this._frame) 
            {
                this._frame.dispose();
                this._frame = null;
            }
            return;
        }

        public static /* const */Number: string="CopyGradeRollLabel.Number";

        public static /* const */Time: string="CopyGradeRollLabel.Time";

        /* internal */ /* var */_gap: int=11;

        /* internal */ /* var */_value: int;

        /* internal */ /* var */_currentValue: int;

        /* internal */ /* var */_type: string;

        /* internal */ /* var */_label: GLabel;

        /* internal */ /* var */_labelValue: GLabel;

        /* internal */ /* var */_frame: FrameTimer;
    }
